package com.bleeth.kettle.util;

import java.io.IOException;
import java.net.ServerSocket;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2021-06-21 11:41
 **/
public class SysUtil {

    private static int RANDOM_PORT = 0;

    public static final int getRandomPort() {
        try {
            if (RANDOM_PORT == 0) {
                ServerSocket s = null;

                s = new ServerSocket(0);

                int randomPort = s.getLocalPort();
                s.close();
                RANDOM_PORT = randomPort;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return RANDOM_PORT;
    }
}
